﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace ImageClipTool.Utils
{
    class SystemUtils
    {
        private static SystemUtils instance;
        public static SystemUtils Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SystemUtils();
                }
                return instance;
            }
        }


        /// <summary>
        /// BitmapImage --> byte[]
        /// </summary>
        /// <param name="bi"></param>
        /// <returns></returns>
        public byte[] ConvertBitmapImageToByteArray(BitmapImage bi)
        {
            MemoryStream memStream = new MemoryStream();
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bi));
            encoder.Save(memStream);
            return memStream.ToArray();
        }

    }
}
